package com.kaifamiao.month05.day09;

public class Demo06 {


    public static void main(String[] args) throws InterruptedException {
        Runnable run = new Runnable() {
            @Override
            public void run() {
                int count = 0;
                while (true) {
                    count++;
                    System.out.println(System.nanoTime() + " : Hello World!");
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                    if (count > 10) {
                        break;
                    }
                }
            }
        };

        Thread t = new Thread(run);
        t.setDaemon(true);
        t.start();

        Thread.sleep(3000);  // 如果主线程已经结束，守护线程也会结束
        System.out.println("main线程结束");
    }
}
